package com.training.bt.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.training.bt.entity.Post;
import com.training.bt.mapper.PostMapper;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PostService extends ServiceImpl<PostMapper, Post> implements IPostService {
    @Override
    public Post createPost(Post post) {
        save(post);
        return post;
    }

    @Override
    public Post getPostById( Long postId) {
        return getById(postId);
    }

    @Override
    public List<Post> getPostsByUserId( Long userId) {
        return baseMapper.selectByUserId(userId);
    }

    @Override
    public List<Post> getAllPosts() {
        return list();
    }

    @Override
    public Post updatePost(Post post) {
        updateById(post);
        return post;
    }

    @Override
    public void deletePost( Long postId) {
        removeById(postId);
    }
    
    
    @Override
    public List<Post> getAllPostsWithCommentCount() {
        return baseMapper.selectAllPostsWithCommentCount();
    }

    @Override
    public Post getPostByIdWithCommentCount(Long postId) {
        return baseMapper.selectPostByIdWithCommentCount(postId);
    }

    @Override
    public List<Post> getPostsByUserIdWithCommentCount(Long userId) {
        return baseMapper.selectPostsByUserIdWithCommentCount(userId);
    }
}